{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "eda34ad4",
   "metadata": {},
   "source": [
    "# 预习"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e8746859",
   "metadata": {},
   "source": [
    "###  思考：什么是有序的数据（Sequence Yype？）\n",
    "* Sequence type有三种：list、tuple、range\n",
    "* 想要有效地处理数据，需要有地方放置这些数据\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eebc8e44",
   "metadata": {},
   "source": [
    "### 1. 数字(Number)类型\n",
    "**python中数字有四种类型：整数、布尔型、浮点数和复数。**\n",
    "\n",
    "1. int (整数), 如 1, 只有一种整数类型 int，表示为长整型，没有 python2 中的 Long。   \n",
    "2. bool (布尔), 如 True。\n",
    "3. float (浮点数), 如 1.23、3E-2\n",
    "4. complex (复数), 如 1 + 2j、 1.1 + 2.2j"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9daabe3c",
   "metadata": {},
   "source": [
    "### 2. 字符串(String)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "314a06e5",
   "metadata": {},
   "source": [
    "\\(在行尾时):续行符<br />\\\\ : 反斜杠符号<br />\\' ：单引号<br />\\\" ：双引号<br />\\a : 响铃<br />\\b : 退格(Backspace)<br />\\n : 换行<br />\\000 ：空<br />\\v ：纵向制表符<br />\\t ：横向制表符<br />\\r ：回车，将 \\r 后面的内容移到字符串开头，并逐一替换开头部分的字符，直至将 \\r 后面的内容完全替换完成\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "71fb92ef",
   "metadata": {},
   "source": [
    "**反斜杠 \\ （转义符）：Python 通常是一行写完一条语句，但如果语句很长，我们可以使用反斜杠 \\ 来实现多行语句<br />使用 r 可以让反斜杠不发生转义。 如 r\"this is a line with \\n\" 则 \\n 会显示，并不是换行。（这里的 r 指 raw，即 raw string，会自动将反斜杠转义）<br /><br />\n",
    "Python 中的字符串有两种索引方式，从左往右以 0 开始，从右往左以 -1 开始。<br />Python 中的字符串不能改变。<br />Python 没有单独的字符类型，一个字符就是长度为 1 的字符串。**\n",
    "\n",
    "* Python 中单引号 ' 和双引号 \" 使用完全相同。   \n",
    "* 使用三引号(''' 或 \"\"\")可以指定一个多行字符串。\n",
    "* 按字面意义级联字符串，如 \"this \" \"is \" \"string\" 会被自动转换为 this is string。\n",
    "* 字符串可以用 + 运算符连接在一起，用 * 运算符重复。\n",
    "* 字符串的截取的语法格式如下：变量[头下标:尾下标:步长]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6615c16e",
   "metadata": {},
   "source": [
    "### 实例："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c98a568e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123456789\n",
      "12345678\n",
      "1\n",
      "345\n",
      "3456789\n",
      "24\n",
      "123456789123456789\n",
      "123456789你好\n",
      "------------------------------\n",
      "hello\n",
      "runoob\n",
      "hello\\nrunoob\n"
     ]
    }
   ],
   "source": [
    "#!/usr/bin/python3\n",
    " \n",
    "str='123456789'\n",
    " \n",
    "print(str)                 # 输出字符串\n",
    "print(str[0:-1])           # 输出第一个到倒数第二个的所有字符\n",
    "print(str[0])              # 输出字符串第一个字符\n",
    "print(str[2:5])            # 输出从第三个开始到第五个的字符\n",
    "print(str[2:])             # 输出从第三个开始后的所有字符\n",
    "print(str[1:5:2])          # 输出从第二个开始到第五个且每隔一个的字符（步长为2）\n",
    "print(str * 2)             # 输出字符串两次\n",
    "print(str + '你好')         # 连接字符串\n",
    " \n",
    "print('------------------------------')\n",
    " \n",
    "print('hello\\nrunoob')      # 使用反斜杠(\\)+n转义特殊字符\n",
    "print(r'hello\\nrunoob')     # 在字符串前面添加一个 r，表示原始字符串，不会发生转义"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "075dedf3",
   "metadata": {},
   "source": [
    "### 存疑："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "8211c579",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "24\n"
     ]
    }
   ],
   "source": [
    "print(str[1:5:2])          # 输出从第二个开始到第五个且每隔一个的字符（步长为2）？？？"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "85db1d38",
   "metadata": {},
   "source": [
    "### 3. Python字符串运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "53a098e8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a + b 输出结果： HelloPython\n",
      "a * 2 输出结果： HelloHello\n",
      "a[1] 输出结果： e\n",
      "a[1:4] 输出结果： ell\n",
      "H 在变量 a 中\n",
      "M 不在变量 a 中\n",
      "\\n\n",
      "\\n\n"
     ]
    }
   ],
   "source": [
    "#!/usr/bin/python3\n",
    " \n",
    "a = \"Hello\"\n",
    "b = \"Python\"\n",
    " \n",
    "print(\"a + b 输出结果：\", a + b)\n",
    "print(\"a * 2 输出结果：\", a * 2)\n",
    "print(\"a[1] 输出结果：\", a[1])\n",
    "print(\"a[1:4] 输出结果：\", a[1:4])\n",
    " \n",
    "if( \"H\" in a) :\n",
    "    print(\"H 在变量 a 中\")\n",
    "else :\n",
    "    print(\"H 不在变量 a 中\")\n",
    " \n",
    "if( \"M\" not in a) :\n",
    "    print(\"M 不在变量 a 中\")\n",
    "else :\n",
    "    print(\"M 在变量 a 中\")\n",
    " \n",
    "print (r'\\n')\n",
    "print (R'\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e713447",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
